package com.agriculture.competition.controller;

import com.agriculture.common.core.utils.poi.ExcelUtil;
import com.agriculture.common.core.web.controller.BaseController;
import com.agriculture.common.core.web.domain.AjaxResult;
import com.agriculture.common.core.web.page.TableDataInfo;
import com.agriculture.common.log.annotation.Log;
import com.agriculture.common.log.enums.BusinessType;
import com.agriculture.competition.domain.JaReport;
import com.agriculture.competition.service.IJaReportService;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 研报信息Controller
 *
 * @author agriculture
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/report")
public class JaReportController extends BaseController {

    @Autowired
    private IJaReportService jaReportService;

    /**
     * 查询研报信息列表
     */
    // @RequiresPermissions("competition:report:list")
    @GetMapping("/list")
    public TableDataInfo list(JaReport jaReport) {
        startPage();
        List<JaReport> list = jaReportService.selectJaReportList(jaReport);
        return getDataTable(list);
    }

    /**
     * 导出研报信息列表
     */
    // @RequiresPermissions("competition:report:export")
    @Log(title = "研报信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JaReport jaReport) {
        List<JaReport> list = jaReportService.selectJaReportList(jaReport);
        ExcelUtil<JaReport> util = new ExcelUtil<JaReport>(JaReport.class);
        util.exportExcel(response, list, "研报信息数据");
    }

    /**
     * 获取研报信息详细信息
     */
    // @RequiresPermissions("competition:report:query")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId) {
        return success(jaReportService.selectJaReportByReportId(reportId));
    }

    /**
     * 新增研报信息
     */
    // @RequiresPermissions("competition:report:add")
    @Log(title = "研报信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JaReport jaReport) {
        return toAjax(jaReportService.insertJaReport(jaReport));
    }

    /**
     * 修改研报信息
     */
    // @RequiresPermissions("competition:report:edit")
    @Log(title = "研报信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JaReport jaReport) {
        return toAjax(jaReportService.updateJaReport(jaReport));
    }

    /**
     * 删除研报信息
     */
    // @RequiresPermissions("competition:report:remove")
    @Log(title = "研报信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds) {
        return toAjax(jaReportService.deleteJaReportByReportIds(reportIds));
    }
}
